package com.ruoyi.generator.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.generator.entity.ClUser;
import com.ruoyi.generator.entity.MaintenancePlan;
import com.ruoyi.generator.entity.PlanAssociation;
import com.ruoyi.generator.entity.bo.MaintenancPlaneBO;
import com.ruoyi.generator.entity.bo.PlanScheduleBO;
import com.ruoyi.generator.entity.bo.PlanScheduleCountBo;
import com.ruoyi.generator.entity.bo.PlanScheduleStaticInfoBO;
import com.ruoyi.generator.po.*;
import com.ruoyi.generator.service.InspectionService;
import com.ruoyi.generator.service.MaintenanceService;
import com.ruoyi.generator.vo.MaintenanceAppVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/maintenance")
public class MaintenanceController extends BaseController {

    @Autowired
    private MaintenanceService maintenanceService;

    @GetMapping("/maintenancedb/list")
    public TableDataInfo list()
    {
        List<MaintenanceScheduleShift> list = maintenanceService.selectScheduleList();
        return getDataTable(list);
    }
    @GetMapping("/maintenancedb/liststatus")
    public TableDataInfo listByStatus(MaintenanceAppVO m)
    {
        startPage();
        List<MaintenanceAppVO> list = maintenanceService.getMaintenanceListByStatus(m);
        return getDataTable(list);
    }
    //下载excel
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaintenanceAppVO m)
    {
        List<MaintenanceAppVO> list = maintenanceService.getMaintenanceListByStatus(m);
        ExcelUtil<MaintenanceAppVO> util = new ExcelUtil<MaintenanceAppVO>(MaintenanceAppVO.class);
        util.exportExcel(response, list, "设备统计");
    }
    @GetMapping("/maintenancedb/getbyrs")
    public TableDataInfo getbyrs()
    {
        ClUser cl=new ClUser();
        cl.setDeptName("保养人员");
        List<ClUser> list = maintenanceService.selectByrs(cl);
        return getDataTable(list);
    }

    @GetMapping("/maintenancedb/count")
    public TableDataInfo countList()
    {
        List<PlanScheduleCountBo> list = maintenanceService.selectMainScheduleCount();
        return getDataTable(list);
    }
    @GetMapping("/maintenancedb/planList")
    public TableDataInfo planList(Maintenance Maintenance)
    {
        startPage();
        List<MaintenancePlan> list = maintenanceService.selectMaintenancePlanList(Maintenance);
        return getDataTable(list);
    }

    @GetMapping("/maintenancedb/getMaintenanceSchedules")
    public TableDataInfo getMaintenanceSchedules()
    {
        System.out.println("device:");
        List<WushuiSchedule> list = maintenanceService.getMaintenanceSchedules();
        return getDataTable(list);
    }

    @PostMapping("/maintenancedb/addMaintenancePlan")
    public AjaxResult addMaintenancePlan(@RequestBody MaintenancPlaneBO maintenancPlaneBO){
        int rows = maintenanceService.addMaintenancePlan(maintenancPlaneBO);
        if (rows != 0){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
//
//    @GetMapping("/db/getUser")
//    public SysUser getUser()
//    {
//        SysUser user = inspectionService.getUser();
//        return user;
//    }
//
//    @GetMapping("/db/deviceList")
//    public TableDataInfo deviceList(Device device)
//    {
//        startPage();
//        List<Device> list = inspectionService.selectDeviceList(device);
//        return getDataTable(list);
//    }
//
//    @GetMapping("/db/getSchedules")
//    public TableDataInfo getSchedules()
//    {
//        System.out.println("device:");
//        List<WushuiSchedule> list = inspectionService.getSchedules();
//        return getDataTable(list);
//    }
//
//    @GetMapping("/db/getDepts")
//    public TableDataInfo getDepts()
//    {
//        System.out.println("device:");
//        List<SysDept> list = inspectionService.getDepts();
//        return getDataTable(list);
//    }
//
//    @GetMapping("/db/getUsers")
//    public TableDataInfo getUsers()
//    {
//        System.out.println("device:");
//        List<SysUser> list = inspectionService.getUsers();
//        return getDataTable(list);
//    }
//
//    @PostMapping("/db/saveEdit")
//    public AjaxResult saveEdit(@RequestBody ScheduleShift scheduleShift)
//    {
//        System.out.println("scheduleShift:"+scheduleShift);
//        return inspectionService.saveEdit(scheduleShift);
//    }
//    @PostMapping("/db/inspectionRecordUpload")
//    public AjaxResult inspectionRecordUpload(@RequestBody InspectionRecord inspectionRecord)
//    {
//        System.out.println("inspectionRecord:"+inspectionRecord);
//        return inspectionService.inspectionRecordUpload(inspectionRecord);
//    }
//    @PostMapping("/db/faultDeclaration")
//    public AjaxResult faultDeclaration(@RequestBody FaultDeclaration  faultDeclaration)
//    {
//        System.out.println("faultDeclaration:"+faultDeclaration);
//        return inspectionService.faultDeclaration(faultDeclaration);
//    }
//    @PostMapping("/db/addCheckingPlan")
//    public AjaxResult addCheckingPlan(@RequestBody CheckingPlan checkingPlan)
//    {
//        return inspectionService.addCheckingPlan(checkingPlan);
//    }
//
//    @GetMapping(value = "/db/getPlan")
//    public TableDataInfo getPlan(String planName)
//    {
//        System.out.println("planName:"+planName);
//        List<SpotCheckPlan> plan =inspectionService.getPlan(planName);
//        return getDataTable(plan);
//    }
//    @GetMapping(value = "/db/getFaultDeclaration")
//    public TableDataInfo getFaultDeclaration()
//    {
//        List<FaultDeclaration> plan =inspectionService.getFaultDeclaration();
//        return getDataTable(plan);
//    }
//    @GetMapping(value = "/db/getInspectionRecord")
//    public TableDataInfo getInspectionRecord()
//    {
//        List<InspectionRecord> plan =inspectionService.getInspectionRecord();
//        return getDataTable(plan);
//    }
//
//    @GetMapping(value = "/db/restore/{period}")
//    public AjaxResult restore(@PathVariable String period)
//    {
//        return success(inspectionService.restore(period));
//    }

}
